//
//  XYTest.m
//  RunTimeTest
//
//  Created by yao zhaofeng on 2018/3/27.
//  Copyright © 2018年 YaoZhaofeng. All rights reserved.
//

#import "XYTest.h"
#import <objc/runtime.h>
#import <UIKit/UIKit.h>

@implementation XYTest

- (id)init {
    if (self = [super init]) {
        [self getIMPLFromSelector:@selector(aaa)];
        [self getIMPLFromSelector:@selector(test1)];
        [self getIMPLFromSelector:@selector(test2)];
//        [self performSelector:@selector(test1) withObject:nil afterDelay:0.5 inModes:@[UITrackingRunLoopMode, NSDefaultRunLoopMode]];
    }
    
    return self;
}

- (void)test1 {
    NSLog(@"test1");
}

+ (void)test2 {
    NSLog(@"test2");
}

/*
 *class_getMethodImplementation
 *method_getImplementation
 */
- (void)getIMPLFromSelector:(SEL)aSelector {
    //first
    IMP instanceIMP1 = class_getMethodImplementation(objc_getClass("XYTest"), aSelector);
    IMP classIMP1 = class_getMethodImplementation(objc_getMetaClass("XYTest"), aSelector);
    
    //second
    Method instanceMethod = class_getInstanceMethod(objc_getClass("XYTest"), aSelector);
    IMP instanceIMP2 = method_getImplementation(instanceMethod);
    
    Method classMethod1 = class_getClassMethod(objc_getClass("XYTest"), aSelector);
    IMP classIMP2 = method_getImplementation(classMethod1);
    
    Method classMethod2 = class_getClassMethod(objc_getMetaClass("XYTest"), aSelector);
    IMP classIMP3 = method_getImplementation(classMethod2);
    
    NSLog(@"instance1:%p  instance2:%p class1:%p class2:%p class3:%p", instanceIMP1, instanceIMP2, classIMP1, classIMP2, classIMP3);
}

@end
